package py.com.alfa.escriba.config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.springframework.context.ApplicationContext;

public class ResourceProvider {
	
	private static Properties props = null;

	public static Properties getResource(String resource) throws FileNotFoundException, IOException {
		if(props == null){
			
			ApplicationContext appctx = EscribaApplicationContextProvider.getContext();
		    ConfigLocator config = ((ConfigLocator) appctx.getBean("configLocator"));
		    
			StringBuffer confPath = new StringBuffer();
			confPath.append(config.getFilePath());
			confPath.append("/apps/previa/");
			confPath.append(resource);
			InputStream stream = new FileInputStream(confPath.toString());

			props = new Properties();
			props.load(stream);
		}
		return props;
	}

}
